/* 用户信息 */
const storeScore = {
    state: {
        token: '',
        userId: '',
        userName: ''
    },
    mutations: {
        // 设置用户信息
        setUserInfo (state, res) {
            state.token = res.token
            state.userId = res.userId
            state.userName = res.userName
        },
        // 重置用户信息
        resetUserInfo(state) {
            window.ssaSdk.loginOut()
            state.token = ''
            state.userId = ''
            state.userName = ''
        }
    },
    actions: {
        // 登录
        loginActions ({ commit }, data) {
            console.log(data)
            return new Promise((resolve, reject) => {
                setTimeout(() => {
                    let result = {
                        token: '123-456-789',
                        userName: '张三',
                        userId: '11111'
                    }
                    window.ssaSdk.loginIn(result)
                    commit('setUserInfo', result)
                    resolve(result)
                }, 1000)
            })
        }
    },
    getters: {
        token: state => state.token,
        userId: state => state.userId,
        userName: state => state.userName
    }
}
export default storeScore
